#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "poker.h"

POKER_CARD RED_JOKER = {HEARTS, JOKER};
POKER_CARD BLACK_JOKER = {SPADES, JOKER};
POKER_CARD POKER_CARDS[] = {
    /* SPADES */
    {SPADES, TWO},
    {SPADES, THREE},
    {SPADES, FOUR},
    {SPADES, FIVE},
    {SPADES, SIX},
    {SPADES, SEVEN},
    {SPADES, EIGHT},
    {SPADES, NINE},
    {SPADES, TEN},
    {SPADES, JACK},
    {SPADES, QUEEN},
    {SPADES, KING},
    {SPADES, ACE},
    /* HEARTS */
    {HEARTS, TWO},
    {HEARTS, THREE},
    {HEARTS, FOUR},
    {HEARTS, FIVE},
    {HEARTS, SIX},
    {HEARTS, SEVEN},
    {HEARTS, EIGHT},
    {HEARTS, NINE},
    {HEARTS, TEN},
    {HEARTS, JACK},
    {HEARTS, QUEEN},
    {HEARTS, KING},
    {HEARTS, ACE},
    /* CLUBS */
    {CLUBS, TWO},
    {CLUBS, THREE},
    {CLUBS, FOUR},
    {CLUBS, FIVE},
    {CLUBS, SIX},
    {CLUBS, SEVEN},
    {CLUBS, EIGHT},
    {CLUBS, NINE},
    {CLUBS, TEN},
    {CLUBS, JACK},
    {CLUBS, QUEEN},
    {CLUBS, KING},
    {CLUBS, ACE},
    /* DIAMONDS */
    {DIAMONDS, TWO},
    {DIAMONDS, THREE},
    {DIAMONDS, FOUR},
    {DIAMONDS, FIVE},
    {DIAMONDS, SIX},
    {DIAMONDS, SEVEN},
    {DIAMONDS, EIGHT},
    {DIAMONDS, NINE},
    {DIAMONDS, TEN},
    {DIAMONDS, JACK},
    {DIAMONDS, QUEEN},
    {DIAMONDS, KING},
    {DIAMONDS, ACE},
};

char *get_poker(const POKER_CARD poker_card)
{
    char *color = get_color(poker_card);
    char *suit = get_suit(poker_card);
    int len = strlen(color) + strlen(suit) + 1;
    char *result = (char *)malloc(len * sizeof(char));
    strcpy(result, color);
    strcat(result, suit);
    return result;
}

char *get_color(const POKER_CARD poker_card)
{
    char *color;
    switch (poker_card.color)
    {
    case SPADES:
        color = "黑桃";
        break;
    case HEARTS:
        color = "红桃";
        break;
    case CLUBS:
        color = "梅花";
        break;
    case DIAMONDS:
        color = "方块";
        break;
    default:
        color = "王";
        break;
    }

    return color;
}

char *get_suit(const POKER_CARD poker_card)
{
    char *suit;
    switch (poker_card.suit)
    {
    case JOKER:
        suit = "王";
        break;
    case TWO:
        suit = "2";
        break;
    case THREE:
        suit = "3";
        break;
    case FOUR:
        suit = "4";
        break;
    case FIVE:
        suit = "5";
        break;
    case SIX:
        suit = "6";
        break;
    case SEVEN:
        suit = "7";
        break;
    case EIGHT:
        suit = "8";
        break;
    case NINE:
        suit = "9";
        break;
    case TEN:
        suit = "10";
        break;
    case JACK:
        suit = "J";
        break;
    case QUEEN:
        suit = "Q";
        break;
    case KING:
        suit = "K";
        break;
    case ACE:
        suit = "A";
        break;
    default:
        suit = "王";
        break;
    }

    return suit;
}